﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reflection;

namespace Xceed.Silverlight.DataGrid
{
  internal class FieldDescriptor
  {
    public FieldDescriptor(
      string name,
      string displayName,
      PropertyInfo propertyInfo,
      string bindingPath,
      bool readOnly,
      bool overrideReadOnlyForInsertion,
      bool browsable)
    {
      if( name == null )
        throw new ArgumentNullException( "name" );

      if( displayName == null )
        throw new ArgumentNullException( "displayName" );

      this.ReadOnly = readOnly;
      this.OverrideReadOnlyForInsertion = overrideReadOnlyForInsertion;
      m_name = name;
      m_displayName = displayName;
      m_propertyInfo = propertyInfo;
      m_bindingPath = bindingPath;
      this.Browsable = browsable;
    }

    #region Name PROPERTY

    public string Name
    {
      get
      {
        return m_name;
      }
    }

    private string m_name; // = null

    #endregion Name PROPERTY

    #region DisplayName PROPERTY

    public string DisplayName
    {
      get
      {
        return m_displayName;
      }
    }

    private string m_displayName; // = null

    #endregion DisplayName PROPERTY

    #region BindingPath PROPERTY

    public string BindingPath
    {
      get
      {
        return m_bindingPath;
      }
    }

    private string m_bindingPath; // = null

    #endregion BindingPath PROPERTY   

    #region PropertyInfo PROPERTY

    public PropertyInfo PropertyInfo
    {
      get
      {
        return m_propertyInfo;
      }
    }

    private PropertyInfo m_propertyInfo; // = null

    #endregion PropertyInfo PROPERTY

    #region ReadOnly PROPERTY

    public bool ReadOnly
    {
      get
      {
        return ( ( m_flags & FieldDescriptorFlags.ReadOnly ) == FieldDescriptorFlags.ReadOnly );
      }
      private set
      {
        bool logicalValue = ( ( m_flags & FieldDescriptorFlags.ReadOnly ) == FieldDescriptorFlags.ReadOnly );
        if( logicalValue != value )
        {
          m_flags ^= FieldDescriptorFlags.ReadOnly;
        }
      }
    }

    #endregion ReadOnly PROPERTY

    #region OverrideReadOnlyForInsertion Property

    public bool OverrideReadOnlyForInsertion
    {
      get
      {
        return ( ( m_flags & FieldDescriptorFlags.OverrideReadOnlyForInsertion ) == FieldDescriptorFlags.OverrideReadOnlyForInsertion );
      }
      private set
      {
        bool logicalValue = ( ( m_flags & FieldDescriptorFlags.OverrideReadOnlyForInsertion ) == FieldDescriptorFlags.OverrideReadOnlyForInsertion );
        if( logicalValue != value )
        {
          m_flags ^= FieldDescriptorFlags.OverrideReadOnlyForInsertion;
        }
      }
    }

    #endregion OverrideReadOnlyForInsertion Property

    #region Browsable Property

    public bool Browsable
    {
      get
      {
        return ( ( m_flags & FieldDescriptorFlags.Browsable ) == FieldDescriptorFlags.Browsable );
      }
      private set
      {
        bool logicalValue = ( ( m_flags & FieldDescriptorFlags.Browsable ) == FieldDescriptorFlags.Browsable );
        if( logicalValue != value )
        {
          m_flags ^= FieldDescriptorFlags.Browsable;
        }
      }
    }

    #endregion Browsable Property

    #region Private Fields

    private FieldDescriptorFlags m_flags;

    #endregion

    #region FieldDescriptor Flags

    [Flags]
    private enum FieldDescriptorFlags : byte
    {
      None=0,
      ReadOnly = 1,
      SupportDBNull = 2,
      Browsable = 4,
      IsASubRelationship = 8,
      IsForeignKey = 16,
      OverrideReadOnlyForInsertion = 32,
      IsDataGridUnboundItemProperty = 64
    }

    #endregion
  }
}
